//
//  Comparison_View.m
//  SecondPage
//
//  Created by winston on 13-4-10.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "Comparison_View.h"
#import "ComparisonTableView.h"


@implementation Comparison_View

- (id)initWithFrame:(CGRect)frame autoID:(NSString*)_autoID ModuleID:(NSString *)_moduleID
{
    self = [super initWithFrame:frame autoID:_autoID ModuleID:_moduleID];
    if(self)
    {
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onAddCompareCar:) name:@"Notification_AddCompareCar" object:nil];
        
        UIImage *img=[UIImage imageNamed:@"AllAuto_Comparison_Image_BG"];
        img=[img stretchableImageWithLeftCapWidth:15 topCapHeight:12];

        
        UIImageView * tablebackground = [[UIImageView alloc] initWithFrame:CGRectMake(15, 45, self.frame.size.width-30, self.frame.size.height-75)];
        [self addSubview:tablebackground];
        [tablebackground release];
        [tablebackground setImage:img];
        
        
        [self renderTemplate];
    }
    return self;
}

-(void)renderTemplate
{
    if(tableView==nil)
    {
        tableView = [[ComparisonTableView alloc]initWithFrame:CGRectMake(20, 45, self.frame.size.width-40, self.frame.size.height-85)];
        [self addSubview:tableView];
        [tableView release];
    }
    
    NSInteger defaultAutoID = [[ResourceLoader getInstance]getHondaCar:self.autoID];
    
    if(defaultAutoID>0)
    {
       [tableView addCompareCar:defaultAutoID];
    }
}


-(void)onAddCompareCar:(NSNotification*)notify
{
    NSInteger specId = [[[notify userInfo]objectForKey:@"SpecID"]intValue];
    
    [tableView addCompareCar:specId];
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

@end
